<div class="x-body">
    <form class="layui-form" data-form='{:request()->url()}'>

        <div class="layui-form-item" pane>
            <label for="cid" class="layui-form-label">
                <span class="x-red">*</span>上级分类
            </label>
            <div class="layui-input-inline">
                <select id="cid" name="cid" required="" lay-verify="required">
                    <option value="0">请选择上级分类</option>
                    {volist name="cates" id="c"}
                    <option value="{$c.id}" {if (isset($vo.cid) and $vo.cid == $c.id) or (!isset($vo.id) and $Request.get.cid !="" and $Request.get.cid == $c.id)}selected{/if}>{$c._pre}{$c.title}</option>
                    {/volist}
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>上级分类
            </div>
        </div>

        <div class="layui-form-item" pane>
            <label for="title" class="layui-form-label">
                <span class="x-red">*</span>文章标题
            </label>
            <div class="layui-input-block">
                <input type="text" id="title" name="title" required="" lay-verify="required"
                value="{$vo.title|default=''}" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="keyword" class="layui-form-label">
                <span class="x-red">*</span>关键词（标签）
            </label>
            <div class="layui-input-block">
                <input type="text" id="keyword" name="keyword" required="" lay-verify="required"
                       value="{$vo.keyword|default=''}" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label for="keyword" class="layui-form-label">
                <span class="x-red">*</span>缩略图
            </label>
            <div class="layui-input-inline">
                <button type="button" data-upload="{:url('admin/upload/file')}" data-field="thumb" data-type="images"
                        value="{$vo.thumb|default=''}" class="layui-btn">上传文件</button>
                <input type="hidden" name="thumb"
                       value="{$vo.thumb|default=''}" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <img data-preview="thumb" src="{$vo.thumb|default=''}">
                点击图片删除
            </div>
        </div>

        <div class="layui-form-item">
            <label for="description" class="layui-form-label">
                <span class="x-red">*</span>摘要
            </label>
            <div class="layui-input-block">
                <textarea id="description" name="description" required="" lay-verify="required" class="layui-textarea">{$vo.description|default=''}</textarea>
            </div>
        </div>

        {eq name="Think.config.editor" value="markdown"}
        <div class="layui-form-item">
            <label for="md_content" class="layui-form-label">
                <span class="x-red">*</span>正文
            </label>
            <div class="layui-input-block">
                <div id="md_content_div" style="height: 200px">
                    <textarea id="md_content" name="md_content" hidden>{if isset($vo.md_content)}{$vo.md_content|raw}{/if}</textarea>
                </div>
            </div>
            <div class="layui-form-mid layui-word-aux">
            </div>
        </div>
        {else/}
        <div class="layui-form-item">
            <label for="content" class="layui-form-label">
                <span class="x-red">*</span>正文
            </label>
            <div class="layui-input-block">
                <div id="content_div">{if isset($vo.content)}{$vo.content|raw}{/if}</div>
                <textarea id="content" name="content" hidden></textarea>
            </div>
            <div class="layui-form-mid layui-word-aux">
            </div>
        </div>
        {/eq}

        <div class="layui-form-item layui-hide">
        </div>

        <div class="layui-form-item layui-col-xs10 layui-col-xs-offset2">
            {if isset($vo.id)}<input type="hidden" name="id" value="{$vo.id}">{/if}
            <button class="layui-btn" lay-filter="add" lay-submit="">
                确定
            </button>
        </div>
    </form>
</div>
<script>
    $(function () {
        layui.form.render();
    });
</script>
{eq name="Think.config.editor" value="markdown"}
<script>
    $(function () {
        var editor = editormd("md_content_div", {
            path : "__ADMIN__/lib/editor.md/lib/",
            height : 400,
            imageUpload:true,
            imageUploadURL:'/admin/upload/markdown',
            uploadCallbackURL:'sdgf',
            // saveHTMLToTextarea : true
        });
    });
</script>
{else/}
<script src="__ADMIN__/js/browser-md5-file.min.js"></script>
<script>
    $(function () {
        var E = window.wangEditor;
        var editor = new E('#content_div');
        editor.customConfig.menus = [
            'head',  // 标题
            'bold',  // 粗体
            'fontSize',  // 字号
            'fontName',  // 字体
            'italic',  // 斜体
            'underline',  // 下划线
            'strikeThrough',  // 删除线
            'foreColor',  // 文字颜色
            'backColor',  // 背景颜色
            'link',  // 插入链接
            'list',  // 列表
            'justify',  // 对齐方式
            'quote',  // 引用
            'image',  // 插入图片
            'table',  // 表格
            'video',  // 插入视频
            'code',  // 插入代码
            'undo',  // 撤销
            'redo'  // 重复
        ];
        editor.customConfig.uploadImgServer = '{:url("admin/upload/wangeditor")}';
        editor.customConfig.uploadImgMaxLength = 1;
        var $text1 = $('#content')
        editor.customConfig.onchange = function (html) {
            // 监控变化，同步更新到 textarea
            $text1.val(html)
        }
        editor.create();
        $text1.val(editor.txt.html())
    });
</script>
{/eq}